#ifndef EVENTLOOP_EVENTLOOPTHREAD_H
#define EVNETLOOP_EVENTLOOPTHREAD_H

#include "EventloopFwd.h"
#include "EventloopThreadFwd.h"
#include "thread/Thread.h"
#include "utility/Noncopyable.h"

#include <condition_variable>

class EventloopThread final {
public:
    explicit EventloopThread(const std::string &name = {});
    explicit EventloopThread(
        EventloopThreadInitFunc initFunc, const std::string &name = {});
    ~EventloopThread();

    Eventloop &eventloop() const { return _loop.value().get(); };

    void start();
    void stop();

private:
    NONCOPYABLE(EventloopThread);

    void _func();

    Thread _thread;
    std::condition_variable _cv;
    std::mutex _mutex;
    const EventloopThreadInitFunc _initFunc;
    OptionalEventloopRef _loop;
};


#endif